package com.example.memory.controller;

import com.example.memory.servicde.UploadService;
import com.example.memory.util.FunctionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

import com.example.memory.base.entity.ResultMsg;

@RestController
@RequestMapping("/upload")
public class UploadController {
    @Resource
    UploadService uploadService;

    @PostMapping("/files")
    public ResultMsg upload(MultipartFile[] files, String title, String content) throws IOException {
        if (FunctionUtils.isEmpty(files)) {
            return ResultMsg.error(null, "没有选择文件");
        }
        uploadService.upload(files, title, content);
        return ResultMsg.success(null, "上传成功");
    }
}
